<?php

//echo br(3); ###########################################################################################

	$TEMP->set_file(array('handle' => DIR_VIEW_PROFESSOR . 'students.html'));
	
	$PAGE   = _GET('page');
	$SLID   = _GET('slid');
	$PSID   = _GET('psid');
	$SID    = _GET('sid');
	$HASH   = _GET('hash');
	
	$SECT   = _GET('sect');
	
	$search = _GET('search', false);
	
	if ( empty($search) ) {
		$search = "Search here...";
	}
	
	$getSubj = $DSC->getSubject($SID);
	
	$listProfStudentPerSubjCount = $STUD->getListProfStudentPerSubjCount($SLID, $logUserID, $PSID, $SECT, $search, '', $activeYear); //COUNT

	if( $listProfStudentPerSubjCount > 0 ) {
		$countNum			= 20;
		$pagenum 			= $_GET["page_no"];
		$page_rows 			= $PAGINATION->numPerRow($countNum);
		$last 				= $PAGINATION->lastCeilPerRow($listProfStudentPerSubjCount, $page_rows);
		$pagenum 			= $PAGINATION->pageNumRow($pagenum, $last); 
		$pageLimit 			= $PAGINATION->limitRow($pagenum, $page_rows);
		
		$arrBut				= array('first' 	=> '<img src="' . DIR_IMAGES . 'pagination_first.png" title="First" border="0" />',
									'previous' 	=> '<img src="' . DIR_IMAGES . 'pagination_prev.png" title="Previous" border="0" />',
									'next' 		=> '<img src="' . DIR_IMAGES . 'pagination_next.png" title="Delete" border="0" />',
									'last' 		=> '<img src="' . DIR_IMAGES . 'pagination_last.png" title="Delete" border="0" />',);
		$classCSS			= array('button' 	=> 'pagination-button', 'label' 	=> 'pagination-label');
		$urlGet				= array('page' 		=> $PAGE,
									'slid' 		=> $SLID,
									'psid' 		=> $PSID,
									'sid' 		=> $SID,
									'hash' 		=> $HASH,
									'search'	=> $search);
		
		if( $listProfStudentPerSubjCount > $countNum ) {
			$pagination 	= $PAGINATION->pagination($arrBut, $pagenum, $last, $classCSS, $urlGet);
		}
	}
	
	$listProfStudentPerSubj = $STUD->getListProfStudentPerSubj($SLID, $logUserID, $PSID, $SECT, $search, $pageLimit, $activeYear);



	if ( (!empty($listProfStudentPerSubj)) ) {
		$TEMP->set_block('handle',  'students', 'studentsRow');
		$numCount 	 = 1;
		$bgcolor  	 = LOOPING_F0F;
		$viewPFID	 = '';
		$viewConvert = '';
		foreach($listProfStudentPerSubj as $listProfStudentPerSubjVAlue) {
			
			$studID 	  		= $listProfStudentPerSubjVAlue['stud_idPK'];
			$courseID 	  		= $listProfStudentPerSubjVAlue['course_idFK'];
			$subjectID 	  		= $listProfStudentPerSubjVAlue['subj_idFK'];
			$studSubjLinkerID	= $listProfStudentPerSubjVAlue['stud_subj_linker_idPK'];
			$studGrade			= $listProfStudentPerSubjVAlue['grade'];
			
			$studentSubjectGrades = $STUD->getStudentSubjectGrades($studID, $subjectID, $courseID, $SLID);

			$studSubjDescription  = $studentSubjectGrades['description'];
			$studSubjEquivalence  = $studentSubjectGrades['equivalence'];

			if (!empty($studGrade)) {
				if ( $studGrade == 'INC' )
					$subjDescription = '<span class="font-red">Incomplete</span>';
				elseif ( $studGrade == 'DRP' )
					$subjDescription = '<span class="font-red">Drop</span>';
				else {
					$subjDescription = $studSubjDescription;
				}
			}
			else {
				$subjDescription = $studSubjDescription;
			}
			
			$viewConvert  = '<div class="transfery-convertion" id="transfery_grades'. $studID .'">';
			$viewConvert .= (!empty($studSubjEquivalence)) ? $studSubjEquivalence : '';
			$viewConvert .= '</div>';
			
			$viewPFID  	  = '<div class="transfery-convertion" id="transfery_pfid'. $studID .'">';
			$viewPFID 	 .= (!empty($subjDescription)) ? $subjDescription : '';
			$viewConvert .= '</div>';
			
			$inputGrades = '<input type="hidden" id="id_transfer'. $studID .'" value="' . $studSubjLinkerID . '"/>
							<input type="text" class="input-transfer-text" maxlength="5" value="' . $studGrade . '" id="input_transfer'. $studID .'"/>
							<img src="' . DIR_IMAGES . 'icon/save.png" border="0" id="save_transfer'. $studID .'" class="cursor-pointer margin-transfery-top" onclick="saveGradeInput(\'' . $studID . '\', \'' . $SID . '\', \'' . $courseID. '\', \'' . $SLID . '\',  \'' . $activeYear . '\')"/>';
			
			$TEMP->set_var(array('stud_no'		=> $listProfStudentPerSubjVAlue['stud_no'],
								 'name'			=> $listProfStudentPerSubjVAlue['last_name'] . ', ' . $listProfStudentPerSubjVAlue['first_name'] . ' ' . substr($listProfStudentPerSubjVAlue['middle_name'],0,1) .'.',
								 'section'		=> $listProfStudentPerSubjVAlue['section_desc'],
								 'grades'		=> $inputGrades,
								 'convertion'	=> $viewConvert,
								 'description'	=> $viewPFID,
								 'numbering'	=> $numCount,
								));
			
			$TEMP->parse('studentsRow', 'students', true);
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$numCount++;
			
		}
	}
	else {
		$TEMP->set_var(array('stud_no'		=> '',
							 'name'			=> 'No Record Found',
							 'section'		=> '',
							 'grades'		=> '',
							 'convertion'	=> '',
							 'description'	=> '',
							 'numbering'	=> '',
							));
	}
	
	$sectionProfList = $STUD->getListSectionProfStudenPerSubj($SLID, $logUserID, $PSID, $SECT);
	
	if ( !empty($sectionProfList) ) {
		$selectSections   = '<select name="sect" id="select_section" class="search-image-design-other-selector-select" onchange="selectSection()">';
		$selectSections  .= '<option value="0">---- All Section ----</option>';
		foreach($sectionProfList as $sectionProfListVal) {
			$sectionSelector  = ($sectionProfListVal['section_idPK'] == $SECT) ? " selected='selected'" : '';		
			$selectSections  .= '<option class="checklist-course-option" value="' . $sectionProfListVal['section_idPK'] . '" ' . $sectionSelector . '>' . $sectionProfListVal['section_desc'] . '</option>';
		}
		$selectSections .= '</select>';
	}
	
	$TEMP->set_var(array('pagination'		=> $pagination,
						 'prof_sub_menu'	=> $pageLib->professorSubMenu(DIR_IMAGES),
						 'subject_desc'		=> $getSubj['subj_desc'],
						 'subject_code'		=> $getSubj['subj_code'],
						 'results'			=> "<strong>" . $listProfStudentPerSubjCount . "</strong>",
						 'select_section'	=> $selectSections,
						 'page' 			=> $PAGE,
						 'slid' 			=> $SLID,
						 'psid' 			=> $PSID,
						 'sid' 				=> $SID,
						 'hash' 			=> $HASH,
						 'search' 			=> $search,
						));
?>